#include "bdpp/bdpp.h"
#include "gtest/gtest.h"

TEST(Int32, BasicAssertions) {
  EXPECT_EQ(std::numeric_limits<int32_t>::max(), 2147483647);
  EXPECT_EQ(std::numeric_limits<int32_t>::min(), -2147483648);
  EXPECT_EQ(std::numeric_limits<int64_t>::max(), 9223372036854775807);
  int32_t output;
  EXPECT_TRUE(bd::parse_int32("2147483647", &output));
  EXPECT_EQ(output, 2147483647);
  EXPECT_TRUE(bd::parse_int32("-2147483648", &output));
  EXPECT_EQ(output, -2147483648);
  EXPECT_TRUE(bd::parse_int32("-0", &output));
  EXPECT_EQ(output, 0);
  EXPECT_TRUE(!bd::parse_int32("-+ 0", &output));
  EXPECT_EQ(output, 0);
  EXPECT_TRUE(!bd::parse_int32("2147483648", &output));
  EXPECT_EQ(output, 0);
  EXPECT_TRUE(!bd::parse_int32("-21474836480", &output));
  EXPECT_EQ(output, 0);
  EXPECT_TRUE(!bd::parse_int32("9223372036854775807", &output));
  EXPECT_EQ(output, 0);
  EXPECT_TRUE(!bd::parse_int32("92233720368547758070", &output));
  EXPECT_EQ(output, 0);
}

TEST(Double, BasicAssertions) {
  double output;
  EXPECT_TRUE(bd::parse_double("21474.83647", &output));
  EXPECT_DOUBLE_EQ(output, 21474.83647);
}

TEST(Truthy, BasicAssertions) {
  EXPECT_TRUE(!bd::check_truthy("0"));
  EXPECT_TRUE(!bd::check_truthy("F"));
  EXPECT_TRUE(!bd::check_truthy("off"));
  EXPECT_TRUE(!bd::check_truthy("NO"));
  EXPECT_TRUE(!bd::check_truthy("False"));
  EXPECT_TRUE(bd::check_truthy("1"));
  EXPECT_TRUE(bd::check_truthy("t"));
  EXPECT_TRUE(bd::check_truthy("True"));
  EXPECT_TRUE(bd::check_truthy("ON"));
}